cd ${work}5_reg_analysis

use input\sample_it, clear

*outcomes
preserve
	use input\firm_it, clear
	keep jurnr year employees sales profits investments equity assets nace4
	foreach v of varlist sales profits investments equity assets {
		replace `v'=`v'/1e3
	}
	deflate sales profits investments equity assets
	save temp\temp, replace
restore
merge 1:1 jurnr year using temp\temp, keep(3) nogen
erase temp\temp.dta

preserve
	use input\fire_it, clear
	keep jurnr year capital wagebill expenditures purchase_buildings purchase_energy purchase_opeq rent inventory credit prepayments dividends
	foreach v of varlist capital wagebill expenditures purchase_buildings purchase_energy purchase_opeq rent inventory credit prepayments dividends {
		replace `v'=`v'/1e3
	}
	deflate capital wagebill expenditures purchase_buildings purchase_energy purchase_opeq rent inventory credit prepayments dividends
	save temp\temp, replace
restore
merge 1:1 jurnr year using temp\temp, keep(1 3) nogen
erase temp\temp.dta

preserve
	use input\export_raw_ipdt, clear
	collapse (sum) vrd_exp=vrd, by(jurnr year)
	replace vrd_exp=vrd_exp/1e3
	deflate vrd_exp
	save temp\temp, replace
restore	
merge 1:1 jurnr year using temp\temp, keep(1 3) nogen
erase temp\temp.dta
replace vrd_exp=0 if vrd_exp==.	

preserve
	use input\import_ipdt, clear
	collapse (sum) vrd_imp=vrd, by(jurnr year)
	replace vrd_imp=vrd_imp/1e3
	deflate vrd_imp
	save temp\temp, replace
restore	
merge 1:1 jurnr year using temp\temp, keep(1 3) nogen
erase temp\temp.dta
replace vrd_imp=0 if vrd_imp==.	

*label
lab var profits "Profits"
lab var employees "Employees"
lab var investments "Investments"
lab var assets "Assets"
lab var equity "Equity"
lab var inventory "Inventory"
lab var purchase_buildings "Purchases, land and buildings"
lab var purchase_energy "Purchases, energy"
lab var wagebill "Wagebill"
lab var purchase_opeq "Purchases, operational equipment"
lab var credit "Receivables"
lab var rent "Rent"
lab var dividends "Dividends" 
lab var prepayments "Prepaid expenses"
lab var capital "Capital stock"
lab var expenditures "Purchases, raw materials"
lab var vrd_exp "Exports"
lab var vrd_imp "Imports"
lab var sales "Sales"

*table
eststo cov_sum : qui estpost sum profits employees investments assets equity inventory purchase_buildings purchase_energy wagebill purchase_opeq credit dividends rent prepayments capital expenditures vrd_exp vrd_imp sales
						
esttab cov_sum cov_sum using output\table_a2 , replace booktabs label se ///
cells( "mean( pattern(1 0) fmt(a3) ) sd( par pattern(0 1) fmt(a3) )" ) ///
mtitles("Mean" "SD") ///
stats(N, labels("N") fmt(%10.0fc)) ///
nonotes collabels(none)	

